#include"BirdImspluseContactListener.h"
#include"Box2D/Box2D.h"
#include"BirdImpluse.h"
#include"Tool.h"

BirdImpluseContactListener::BirdImpluseContactListener(BirdImpluse * main)
{
}

void BirdImpluseContactListener::PostSolve(b2Contact * contact, const b2ContactImpulse * impulse)
{
	b2Body* checkA = contact->GetFixtureA()->GetBody();
	b2Body* checkB = contact->GetFixtureB()->GetBody();
	auto result = checkWithTarget(checkA, checkB, app->bird, app->stone);
	if (result.size() > 0)
	{
		imp=impulse->normalImpulses[0];
		isContacted = true;
	}
}

std::vector<b2Body*> BirdImpluseContactListener::checkWithTarget(b2Body * checkA, b2Body * checkB, b2Body * targetA, b2Body * targetB)
{
	std::vector<b2Body*> checkResult;
	if (checkA == targetA && checkB == targetB)
	{
		checkResult.push_back(checkA);
		checkResult.push_back(checkB);
	}
	else if (checkA == targetB && checkB == targetA)
	{
		checkResult.push_back(checkB);
		checkResult.push_back(checkA);
	}
	return checkResult;
}
